//
//  CSNavigationController.m
//  classroom
//
//  Created by Macx on 16/7/30.
//  Copyright © 2016年 LiuZhuo. All rights reserved.
//

#import "CSNavigationController.h"

@interface CSNavigationController ()

@end

@implementation CSNavigationController
+(void)initialize{
    // 取出导航条Item 的 外观对象
    UIBarButtonItem * btn = [UIBarButtonItem appearance];
    
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    dict[NSForegroundColorAttributeName] = [UIColor colorWithRed:0/255.0 green:155/255.0 blue:238/255.0 alpha:1.0];
    [btn setTitleTextAttributes:dict forState:UIControlStateNormal];
#warning 这个attributes 只对 normal有效
    // 不能用
    NSMutableDictionary * dict1 = [NSMutableDictionary dictionary];
    dict1[NSForegroundColorAttributeName] = [UIColor grayColor];
    [btn setTitleTextAttributes:dict1 forState:UIControlStateDisabled];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    UIBarButtonItem * bar = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(back)];
//    self.navigationItem.leftBarButtonItem = bar;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    
    // 0.判断是否是栈底控制器
    if (self.childViewControllers.count > 0) {
//        // 不是栈底控制器, 需要添加左边和右边按钮
//        // 1.设置左边按钮
        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImage:@"navigationbar_back" hightLightImage:@"navigationbar_back_highlighted" target:self action:@selector(back)];
//
//        // 2.设置右边按钮
        viewController.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithImage:@"navigationbar_more"  hightLightImage:@"navigationbar_more_highlighted" target:self action:@selector(more)];
        viewController.hidesBottomBarWhenPushed = YES;
    }
    
    [super pushViewController:viewController animated:animated];
}


- (void)back
{
    [self popViewControllerAnimated:YES];
}

- (void)more
{
    [self popToRootViewControllerAnimated:YES];
}

@end
